package com.kedacom.ctsp.authz.security.provider;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.session.SessionRegistry;

/**
 * 用户session与token存储
 *
 * @author xuwei
 * @create 2017-11-30 11:34
 **/
@Configuration
@ConditionalOnClass(RedisTemplate.class)
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisSessionRegistryConfiguration {

    @Bean
    @ConditionalOnMissingBean(SessionRegistry.class)
    protected SessionRegistry redisSessionRegistry() {
        return new RedisSessionRegistryImpl();
    }

    @Bean
    @ConditionalOnMissingBean(TokenManager.class)
    protected RedisTokenManager redisTokenManager() {
        return new RedisTokenManager();
    }
}
